<template>
  <div class="login-container">
    <!-- 登录表单区域 -->
    <div class="login-box">
      <!-- 标题区域 -->
      <div class="title-section">
        <h1 class="system-title">临平娱乐GIS</h1>
      </div>

      <!-- 登录表单 -->
      <div class="login-form">
        <h2 class="form-title">用户登录</h2>
        <div class="form-container">
          <div class="form-group">
            <label for="username" class="icon-label">
              <img src="../assets/images/user.png" alt="用户图标" class="input-icon">
            </label>
            <input type="text" id="username" v-model="username" placeholder="请输入用户名">
          </div>
          <div class="form-group">
            <label for="password" class="icon-label">
              <img src="../assets/images/password.png" alt="密码图标" class="input-icon">
            </label>
            <input type="password" id="password" v-model="password" placeholder="请输入密码">
          </div>
          <button class="login-btn" @click="handleLogin">登录</button>
          <div v-if="errorMessage" :class="['error-message', { 'show': errorMessage }]">{{ errorMessage }}</div>
        </div>
        <div class="login-footer">
          <div class="logo-container">
            <img src="../assets/images/logo/logo.png" alt="公司logo" class="company-logo">
            <div class="company-info">
              <p class="company-name">杭州晟麟通信技术有限公司</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';

const router = useRouter();

const username = ref('');
const password = ref('');
const errorMessage = ref('');
const userMap = [
  {
  username: 'admin',
  password: '123456'
  },
  {
    username: 'admin123',
    password: 'Sl@445566'
  }
]
const handleLogin = () => {
  // 简单登录验证
  if (userMap.find(item => item.username == username.value && item.password == password.value)) {
    // 存储登录状态
    localStorage.setItem('user', username.value);
    sessionStorage.setItem('isLoggedIn', 'true');
    // 跳转到地图首页
    router.push('/');
  } else if (username.value == '' || password.value == '') {
    errorMessage.value = '请输入用户名和密码';
    // 3秒后自动清除错误消息
    setTimeout(() => {
      errorMessage.value = '';
    }, 3000);
  } else {
    errorMessage.value = '用户名或密码错误';
    // 3秒后自动清除错误消息
    setTimeout(() => {
      errorMessage.value = '';
    }, 3000);
  }
};
</script>

<style>
* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  overflow: hidden !important;
}

body {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

::-webkit-scrollbar {
  display: none;
}
</style>

<style scoped>
.login-container {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden !important;
  background-image: url('../assets/images/background.png');
  background-size: cover;
  background-position: center;
  background-attachment: fixed;
  background-repeat: no-repeat;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 0;
  margin: 0;
}

@media (max-width: 768px) {
  .login-container {
    background-attachment: scroll;
  }
}

.login-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(15, 23, 42, 0.85);
}

.login-box {
  width: 100%;
  max-width: 420px;
  z-index: 10;
  padding: 20px;
}

@media (max-width: 768px) {
  .login-box {
    padding: 15px;
    max-width: 90%;
  }
  .company-logo {
    width: 50px;
    height: 50px;
  }
  .system-title {
    font-size: clamp(1.2rem, 5vw, 24px);
  }
  .form-container {
    padding: 20px 15px;
  }
}

.title-section {
  text-align: center;
  padding: 15px 5px;
  border-radius: 12px 12px 0 0;
  background: rgba(15, 23, 42, 0.95);
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-bottom: none;
  box-shadow: 0 -5px 15px rgba(0, 240, 255, 0.2);
}

.logo-container {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 15px;
  padding: 10px 5px;
  gap: 8px;
  width: 100%;
}

.company-logo {
  width: clamp(40px, 7vw, 50px);
  height: clamp(40px, 7vw, 50px);
  margin-right: 8px;
}

.company-info {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-width: 0;
}

.system-title {
  font-size: clamp(1.5rem, 5vw, 28px);
  color: #00f0ff;
  margin: 0 0 10px 0;
  text-shadow: 0 0 10px rgba(0, 240, 255, 0.8);
  white-space: nowrap;
  font-weight: bold;
  text-align: center;
  padding: 10px 0;
}

.login-footer {
  margin-top: 30px;
  padding-top: 20px;
  border-top: 1px solid rgba(0, 240, 255, 0.2);
  display: flex;
  justify-content: center;
}

.company-name {
  font-size: 17px;
  color: #e2e8f0;
  margin: 0;
  line-height: 1.5;
}

@media (max-width: 768px) {
  .company-name {
    font-size: clamp(0.9rem, 3vw, 15px);
  }
}

.login-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  padding: 30px;
  box-sizing: border-box;
  background: rgba(15, 23, 42, 0.9);
  border-radius: 0 0 12px 12px;
  border: 1px solid rgba(0, 240, 255, 0.4);
  border-top: none;
  box-shadow: 0 5px 15px rgba(0, 240, 255, 0.25);
}



.form-title {
  font-size: 26px;
  color: #00f0ff;
  margin-bottom: 25px;
  text-shadow: 0 0 8px rgba(0, 240, 255, 0.6);
  padding-bottom: 15px;
  border-bottom: 1px solid rgba(0, 240, 255, 0.2);
  width: 100%;
  text-align: center;
}

.form-container {
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  padding: 20px;
  border-radius: 12px;
  background-color: rgba(30, 41, 59, 0.5);
  border: 1px solid rgba(0, 240, 255, 0.2);
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.1);
}

.form-group {
  width: 100%;
  margin-bottom: 20px;
  padding: 0 20px;
  box-sizing: border-box;
}

@media (max-width: 768px) {
  .form-group {
    margin-bottom: 18px;
    padding: 0 15px;
  }
  .login-btn {
    padding: 12px;
    font-size: 15px;
  }
}

.form-group label {
  display: block;
  margin-bottom: 10px;
  color: #e2e8f0;
  font-size: 14px;
  line-height: 1.5;
}

.icon-label {
  display: flex;
  align-items: center;
}

.input-icon {
  width: 22px;
  height: 22px;
  margin-right: 8px;
  vertical-align: middle;
}

.form-group input {
  width: 100%;
  padding: 14px 15px;
  border: 1px solid rgba(0, 240, 255, 0.3);
  border-radius: 6px;
  font-size: 15px;
  background-color: rgba(30, 41, 59, 0.9);
  color: #e2e8f0;
  margin-top: 5px;
}

.form-group input:focus {
  outline: none;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.6);
  border-color: rgba(0, 240, 255, 0.6);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background-color: rgba(0, 240, 255, 0.2);
  color: #00f0ff;
  border: 1px solid rgba(0, 240, 255, 0.5);
  border-radius: 6px;
  font-size: 16px;
  cursor: pointer;
  box-shadow: 0 0 15px rgba(0, 240, 255, 0.25);
  margin-top: 25px;
  margin-bottom: 15px;
}





.login-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  box-shadow: 0 0 10px rgba(0, 240, 255, 0.15);
}



.error-message {
  color: #ff4d4f;
  font-size: 14px;
  margin-top: 20px;
  padding: 8px 20px;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  background-color: rgba(255, 77, 79, 0.1);
  border-radius: 4px;
}
</style>